function PDBookmarkTree(pdDoc) {
    this.m_pdDoc = pdDoc;
    this.m_firstLevelBookmark = [];
    this.m_firstLevelBookmarkCount = 0;
    this.m_zTree = null;
    this.GetFirstChild = function (parent) {
        if (parent != null)
            return parent.GetFirstChild();
    }
    this.GetNextSibling = function (bk) {
        return bk.GetNextSibling();
    }
    this.GetDocument = function () {
        return m_pdDoc;
    }
}

 PDBookmarkTree.prototype.DrawBookmark = function(jsonData){
	 var setting = {
			view: {
				selectedMulti: false,
				showIcon:false
			},
			data: {
				key: {
					children:"Child",
					name:"Title"
				}
			},
			callback: {
				beforeClick: function(treeId, treeNode) {
					var zTree = $.fn.zTree.getZTreeObj("bookmark");
					var app = PDEApp.prototype.GetApp();
					app.docEx.GotoPage(treeNode.Dest[0]);
				}
			}
		};
	 
	 $.fn.zTree.init($("#bookmark"), setting, jsonData);
	 this.zTree = $.fn.zTree.getZTreeObj("bookmark");
	 var treeArray = this.zTree.transformToArray(jsonData);
	
 }

 PDBookmarkTree.prototype.BuildFormJson = function (jsonData) {
	 var bookmarkTree = this;
	    $.each(jsonData, function (n, u) {
	        if (u != undefined && u != null) {
	            switch (n) {
	                case "ChildCount":
                    bookmarkTree.m_firstLevelBookmarkCount = u;
                    break; 
                case "Child":
                	bookmarkTree.DrawBookmark(u);
                    if(u.length > 0){
                    	bookmarkTree.AppendBookMark(u);
                    }
                    break; 

            }
        }
    });
	 
 }
 
PDBookmarkTree.prototype.AppendBookMark = function(Arr){
	for(var i = 0; i < Arr.length; i++){
		var pdBookmark = new PDBookmark();
		Arr[i] = pdBookmark.FromJson(Arr[i]);
		this.m_firstLevelBookmark.push(pdBookmark);
		if(pdBookmark.m_childs.length > 0){
			this.AppendBookMark(pdBookmark.m_childs);
		}
	}
//	PDBookmark.prototype.ParseToChild(this.m_firstLevelBookmark);
	//this.m_firstLevelBookmark.push(bookMarkObj);
}

function PDBookmark() {
    this.m_Title = "";
    this.m_fontStyle = 0; //1 for italic, 2 for bold
    this.m_fontClr = 0;
    this.m_dest = [];
    
	this.m_childs = [];
    this.m_firstChild = null;
    this.m_childCount = 0;
    this.m_nextSibling = 0;
    
    this.SetTitle = function(title){
        this.m_Title = title;
    }
    this.GetTitle = function(){
        return this.m_Title;
    }
    this.GetFontStyle = function () {
        return this.m_fontStyle;
    }
    this.SetFontStyle = function (style) {
        this.m_fontStyle = style;
    }
    this.SetFontClr = function (clr) {
        this.m_fontClr = clr;
    }
    this.GetFontClr = function () {
        return m_fontClr;
    }
    this.SetDest = function (dest) {
        this.m_dest = dest;
    }
    this.GetDest = function () {
        return this.m_dest;
    }
    //childs
    this.SetFirstChild = function (child) {
        this.m_firstChild = child;
    }
    this.GetFirstChild = function () {
        return m_firstChild;
    }
    this.GetChildCount = function () {
        return m_childCount;
    }

    this.SetChildCount = function (childs) {
        this.m_childCount = childs;
    }
    this.SetNextSibling = function (sibling) {
        this.m_nextSibling = sibling;
    }
    this.GetNextSibling = function () {
        return this.m_nextSibling;
    }
}
   
PDBookmark.prototype.GetColorContext = function (fontColor){
	var b = (fontColor >> 16) & 0xFF;
    var g = (fontColor >> 8) & 0xFF;
    var r = fontColor & 0xFF;
    return "RGB(" + r + "," + g + "," + b + ")";
}